<?php

require_once "core.php";

global $user;

if(!is_object($user) || !$user->isAdmin()) die("NOT DO IT AGAIN!");

start_site();

  // This block of code down is commented because of using phpBB

/*if(isset($_GET['adduser'])){
	if($_GET['adduser'] == "step2"){
		$error == "";
		if($_POST['name'] == "" || strlen($_POST['name']) < 6){
			$error += "\nNazwa uzytkownia nie podana lub zbyt krotka";
		}
		if($_POST['password'] == "" || strlen($_POST['password']) < 6){
			$error += "\nNie podano hasla lub zbyt krotkie";
		}
		if($_POST['access'] == "" || !isnumeric($_POST['access']) || $_POST['access'] < 0 || $_POST['access'] > 8) { // U cannot make site creator (acc: 9)
			$error += "\nNie podano dostepu lub zly";
		}
		if($_POST['status'] == "" || !isnumeric($_POST['status']) || $_POST['status'] < 0 || $_POST['status'] > 3) {
			$error += "\nNie podano statusu lub zly";
		}
		if($error == ""){
			$query = database_query("INSERT INTO `".DATABASE_USERS."` (`name`, `password`, `e-mail`, `registred_time`, `access`, `status`) VALUES ('".$_POST['name']."', '".md5($_POST['password'])."', '".$_POST['e-mail']."', '".time()."', '".$_POST['access']."', '".$_POST['status']."')");
			echo "Dodano<br /><a href='administration.php'>Wróæ</a>";
		}else{
			echo $error;
		}
	}else{
		echo "<form action='administration.php?adduser=step2' method='post'>";
		echo "Nazwa u¿ytkownika* <input type='text' maxlength='255' name='name' /><br />";
		echo "Has³o* <input type='text' maxlength='255' name='password' /><br />";
		echo "E-mail <input type='text' maxlength='255' name'e-mail' /><br />";
		echo "Dostêp: <input type='text' maxlength='1' name='access' value='1' /> (0 - zbanowany lub goæ, 1 - normalny, 8 - administrator, nie da siê ustawic 9!)<br />";
		echo "Status: <input type='text' maxlenght='1' name='status' value='2' /> (0 - zbanowany, 1 - zarejestrowany, nieaktywny, 2 - zarejestrowany, aktywny)<br />";
		echo "<input type='submit' class='button' value='Dodaj' />";
		echo "</form>";
	}
}else*/if(isset($_GET['mysql'])){
	if(isset($_POST['dosomething'])){
		$txt = $_POST['textx'];
		$txt = str_replace("db_usr", DATABASE_USERS, $txt);
		$txt = str_replace("\'", "'", $txt);
		$query = database_query($txt);
		echo "<textarea cols='100' rows='20' class='textbox'>";
		$a = 1;
		while($element = database_array($query)){
			$b = 1;
			echo "\n".$a.".|";
			foreach($element as $elementa){
				echo " ".$b."=>".$elementa;
				$b++;
			}
			$a++;
		}
		echo "</textarea>";
	}
	echo "<form action='administration.php?mysql' method='post'>";
	echo "<input type='textbox' name='textx' size='200'>";
	echo "<input type='submit' name='dosomething' class='button'>";
	echo "</form>";
}else{
	echo "<center><a href='administration.php?mysql'>MySQL</a></center>";
	include "modules-administration.php";
	include "templates/templates-admin.php";
	
	opentable("Administracja galeria zdjec");
	echo "<a href='photogallery.php?add=photo'>Dodaj zdjecie</a><br />";
	echo "<a href='photogallery.php?add=album'>Dodaj album</a><br />";
	echo "<a href='photogallery.php?edit=photo'>Edytuj zdjecie</a><br />";
	echo "<a href='photogallery.php?edit=album'>Edytuj album</a><br />";
	closetable();
	
  // phpBB users
  
	/*opentable("Administracja uzytkownikami");
	echo "<a href='administration.php?adduser'>Dodaj uzytkownika</a><br />";
	echo "<a href='administration.php?deleteuser'>Usun uzytkownika</a><br />";
	echo "<a href='administration.php?banuser'>Zbanuj uzytkownika</a><br />";
	echo "<a href='admministration.php?setuseraccess'>Zmien tryb dostepu uzytkownka</a> (czyli np. ustaw uzytkownika jako admina)<br />";
	closetable();*/
}

end_site();
?>